﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.MemoPattern.GameRole
{
    /// <summary>
    /// 游戏角色
    /// </summary>
    public class GameRole
    {
        /// <summary>
        /// 生命力
        /// </summary>
        private int _vit;
        public int Vitality
        {
            get { return _vit; }
            set { _vit = value; }
        }

        /// <summary>
        /// 攻击力
        /// </summary>
        private int _atk;
        public int Attack
        {
            get { return _atk; }
            set { _atk = value; }
        }

        /// <summary>
        /// 防御力
        /// </summary>
        private int _def;
        public int Defense
        {
            get { return _def; }
            set { _def = value; }
        }

        /// <summary>
        /// 状态显示
        /// </summary>
        public void StateDisplay()
        {
            Console.WriteLine("角色当前状态：");
            Console.WriteLine("体力：{0}", _vit);
            Console.WriteLine("攻击力：{0}", _atk);
            Console.WriteLine("防御力：{0}", _def);
            Console.WriteLine("");
        }

        /// <summary>
        /// 获得初始状态
        /// </summary>
        public void GetInitState()
        {
            _vit = 100;
            _atk = 100;
            _def = 100;
        }

        /// <summary>
        /// 战斗
        /// </summary>
        public void Fight()
        {
            _vit = 0;
            _atk = 0;
            _def = 0;
        }

        /// <summary>
        /// 保存角色状态
        /// </summary>
        /// <returns></returns>
        public RoleStateMemento SaveState()
        {
            return (new RoleStateMemento(_vit, _atk, _def));
        }

        /// <summary>
        /// 恢复角色状态
        /// </summary>
        /// <param name="memento"></param>
        public void RecoveryState(RoleStateMemento memento)
        {
            _vit = memento.Vitality;
            _atk = memento.Attack;
            _def = memento.Defense;
        }
    }
}
